import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react'

// 默认的接口前缀，在 .env 中设置
const apiPrefix = process.env.VUE_APP_API_PREFIX;
// Onlyoffice 接口前缀，在 .env 中设置
const onlyofficeApiPrefix = process.env.VUE_APP_ONLYOFFICE_API_PREFIX;

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [reactRefresh()],
  base:'./',
  build:{target:"chrome58"},
  mode:"development",
  server: {
    host:"0.0.0.0",
    // 修改端口为 3001
    port: 3001,
    proxy: {
      [apiPrefix]: {
        target: 'http://127.0.0.1:3000',
        ws: false,
        changeOrigin: true,
        // Vite 没有 logLevel 选项，可使用 configure 进行日志配置
        configure: (proxy, options) => {
          proxy.on('proxyReq', (proxyReq, req, res) => {
            console.log('Proxying request:', req.url);
          });
        }
      },
      [onlyofficeApiPrefix]: {
        target: 'http://10.0.108.84:9000',
        ws: false,
        changeOrigin: true,
        rewrite: (path) => path.replace(new RegExp(`^${onlyofficeApiPrefix}`), '')
      },
      // 保留原有的代理配置
      '/rest': 'http://127.0.0.1:8000',
    }
  }
})
